<%--
  Created by IntelliJ IDEA.
  User: hsk
  Date: 2021/4/13
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/public/header/permissionCommon.jspf" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="itheima" uri="http://ChanghuXian.com/common/"%>


<html>
<head>
    <title>护理员统计</title>
    <link href="${webPath}/css/Sign/bootstrap.min.css" rel="stylesheet">
    <%@include file="/resources/commons/basejs.jsp" %>
</head>
<body class="layui-layout-body" >
<div class="layui-layout layui-layout-admin">
    <!-- 头部和左侧导航-->
    <div id="header"></div>

    <!--右侧主体区域-->
    <div class="layui-body">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li class="layui-this">护理员统计</li>
            </ul>
            <div class="layui-tab-content">
                <div id="staffDiv" class="layui-tab-item layui-show">
                    <%----------- 信息表格 显示------------%>
                    <table class="layui-hide" id="showstaff" lay-filter="staff" ></table>
<%--                    搜索年份以及机构--%>
                    <div class="SearchLoadDepartment" style="font-size: small">
                        <div class="layui-input-inline layui-show" style="width: 100%">

                            <form id="userSearch" class="layui-form layui-form-pane layui-input-inline" method="post"
                              style="margin-top: 20px;width: 60%">
                                <div class="layui-form-item" style="width:100%">

                                    <label class="layui-form-label" style="width: auto">搜索年份</label>
                                    <div class="layui-input-inline" style="width: auto">
                                        <select name="yearSearch" id="yearSearch"  lay-filter="yearSearch" >
                                            <option value="">请选择年份</option>
            <%--                                这里被写死了？--%>
                                            <option value="2021">2021年</option>
                                            <option value="2020">2020年</option>
                                            <option value="2019">2019年</option>
                                        </select>
                                    </div>

                                    <label class="layui-form-label" style="width: auto">搜索护理机构</label>
                                    <div class="layui-input-inline" style="width: auto" >
                                        <select name="getServorg" id="getServorg" lay-filter="getServorg" value={getServorg} class="select">
                                            <option value="">请选择护理机构</option>
<%--                                            <option value="">嘉定护理站一号</option>--%>
                                        </select>
                                    </div>


                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    <button class="layui-btn" lay-submit lay-filter="searchSubmit" style="width: auto">
                                        <i class="layui-icon">&#xe615;</i>查询
                                    </button>
                                </div>

                            </form>
                            <div class="layui-inline" style="float: right;margin-top: 20px">
                                <button class="layui-btn" id="exportExcel" name="exportExcel" style="width: auto;float: right;border-radius: 5px;margin-left: 5px;">
                                    <i class="layui-icon layui-icon-export"></i>
                                    <div class="layui-inline" style="font-size: small;text-align:center;margin-top: -3px">导出文件</div>
                                </button>
                            </div>
                        </div>
                        <%-------------文件导出-------------%>

                    </div>
<%--                            --------- 信息表格 显示------------%>
                    <table class="layui-hide" id="showyear" lay-filter="year" ></table>

<%--                </div>--%>
<%--            </div>--%>

<%--    </div>--%>
<%--                    <div class="SearchLoadDepartment" style="font-size: small">--%>
<%--                        搜索年份：--%>
<%--                        <div class="layui-input-inline layui-form" style="width: 150px">--%>
<%--                            <select name="yearSearch" id="yearSearch" lay-filter="yearSearch">--%>
<%--&lt;%&ndash;                            <select name="yearSearch" id="yearSearch" lay-filter="yearSearch" class="select">&ndash;%&gt;--%>
<%--                                <option value="">请选择年份</option>--%>
<%--                                <option value="2021">2021年</option>--%>
<%--                                <option value="2020">2020年</option>--%>
<%--                                <option value="2019">2019年</option>--%>
<%--                            </select>--%>
<%--                        </div>--%>
<%--                        <div class="layui-inline">--%>
<%--                            <button class="searchBtn" lay-submit lay-filter="searchSubmit" data-type="reload1" style="margin-left:10px;height:30px;width:85px;background-color: #009688;color: white;border: none;border-radius: 5px">--%>
<%--                                <i class="layui-icon layui-icon-search"></i>--%>
<%--                                <div class="layui-inline" style="font-size: small;text-align:center;margin-top: -6px;margin-left: 5px;margin-right: 5px">搜 索</div>--%>
<%--                            </button>--%>
<%--                        </div>--%>
<%--                        &lt;%&ndash;-----------文件导出-----------&ndash;%&gt;--%>
<%--                        <div class="layui-inline" style="float: right">--%>
<%--                            <button class="layui-btn layui-btn-sm" id="exportExcel" name="exportExcel" style="width: 100px;float: right;border-radius: 5px;margin-left: 5px">--%>
<%--                                <i class="layui-icon layui-icon-export"></i>--%>
<%--                                <div class="layui-inline" style="font-size: small;text-align:center;margin-top: -3px">导出文件</div>--%>
<%--                            </button>--%>
<%--                        </div>--%>
<%--                        <table class="layui-hide" id="showyear" lay-filter="year" ></table>--%>
<%--                        --%>
<%--                </div>--%>
            </div>
        </div>

    </div>
</div>
</div>

    <!--底部-->
    <div id="footer"></div>
<%--</div>--%>
    <script>
        $("#header").load("${webPath}/publicPages/permission/fragments/header.jsp");
        $("#footer").load("${webPath}/publicPages/permission/fragments/footer.jsp");
    </script>
    <script type="text/javascript" src="${webPath}/js/permission/dateUtils.js"></script>
    <script type="text/javascript" src="${webPath}/js/StatisticalReport/report.js"></script>

    <%------------------- EXCEL 文件导出------------------%>
    <script type="text/javascript">
        <%--table以及form表单更新--%>
        layui.use(['form',"table","laydate"], function(){
            var form = layui.form,
                table =layui.table,
                laydate =layui.laydate;
            //下拉框动态加入护理机构
            $.ajax({
                type:"POST",
                url:'../statistics/getServorg',  //从数据库查询返回的是个list
                success: function (data) {
                    console.log("护理机构查询", data);
                    $.each(data,function(index,item){
                        $('#getServorg').append(new Option(item.serv_org));//往下拉菜单里添加元素
                        // $('#getServorg').append(new Option(ser_org));//往下拉菜单里添加元素
                    })
                    form.render();//菜单渲染 把内容加载进去
                }
                ,error: function () {
                    alert("查询机构失败！！！")}

            })


            //刷新最下面的表格  监听提交
            form.on('submit(searchSubmit)', function (data) {

                data.field.page = 1;
                data.field.limit = 10;
                console.log('staff统计', data.field);
                //刷新统计合计的表格
                $.ajax({

                    // url: '../statistics/listStaffyear?year='+$("#yearSearch").val(),
                    url: '../statistics/selectByhg',
                    data: data.field,
                    request: {
                        pageName: 'page' //页码的参数名称，默认：page
                        , limitName: 'limit' //每页数据量的参数名，默认：limit
                    },
                    type: "POST",
                    success: function (data) {
                        // console.log("xxxxxx",data.list);
                        console.log("查询到的数据", data);
                        console.log("查询到的数据", data.field);
                        table.reload('year', {
                            url: "",
                            // data:data.list,
                            data: data,
                            done: function () {
                                console.log("完成")
                            }
                        })
                    },//ajax的使用，点击submit即可跳转到controller处寻找url完成功能

                });
                return false;
            });

            // laydate.render({
            //     elem: '#yearSearch',
            // });

        })

        //导出excel表格部分
        layui.config({//配置并导入excel插件
            base: '${base}/js/layui_exts/'
        }).use([ 'form','excel', 'layer'], function() {
            var $ = layui.$;
            var form = layui.form;
            var layer = layui.layer;
            var excel = layui.excel;
            $('#exportExcel').on('click', function(){
                console.log("触发导出按钮");

                //等之后机构加进去之后，要改
                var year = $('#yearSearch');
                var serv_org = $('#getServorg');
                console.log("year.val()",year.val());
                console.log("serv_org.val()",serv_org.val());
                layer.confirm('是否确认导出', function(index,data) {
                    $.ajax({
                        // url:'../statistics/listStaffyear'
                        url:'../statistics/selectByhg'
                        ,method:'post'
                        ,data: {
                            yearSearch: year.val(),
                            getServorg:serv_org.val(),
                        }

                        // ,console.log("data",data)
                        , dataType: 'json'
                        , success(res) {
                            var data = res;
                            console.log("res",res);
                            layer.close(index);
                            data = excel.filterExportData(data, [
                                'time'
                                ,'serv_org'
                                , 'youxiaodaigang'
                                , 'youxiaozaigang'
                                , 'hg_wuxiaozhuanchu'
                            ]);
                            data.unshift({
                                time: "月份", serv_org:"护理站",youxiaodaigang: "有效待岗",
                                youxiaozaigang: "有效在岗", hg_wuxiaozhuanchu: "无效转出",
                            });
                            excel.exportExcel(data, '护理员状态统计导出--' + new Date().toLocaleString() + '.xlsx', 'xlsx');
                        }
                        , error() {
                            layer.alert('获取数据失败，请检查是否部署在本地服务器环境下');
                        }
                    });
                });
            });


        });
    </script>




</body>


</html>
